let app = getApp()
Component({
    properties: {
        page_type:String
      },
      data:{
        type:0,
        placeholder: {
          name: "请输入姓名",
          account: "请输入账号"
      },
      index:0,
      addCardParams: {
          distribution_id:wx.getStorageSync('distribution_id'),
          name: "",
          account: "",
          type: ""
      }
      },
    lifetimes: {
        attached: function () {
           this.setData({
              getGlobalColor:app.globalData.globalColor
           })
           var withdraw_type=JSON.parse(wx.getStorageSync('distribution').withdraw_type)
           for(var i=0;i<withdraw_type.length;i++){
               if(withdraw_type[i]=='wechat'){withdraw_type[i]='微信'}
               if(withdraw_type[i]=='alipay'){withdraw_type[i]='支付宝'}
               if(withdraw_type[i]=='bank_card'){withdraw_type[i]='银行卡'}
           }
           var accountType={
            arr:withdraw_type,
            index: 0
           }
           console.log(accountType)
          
           this.setData({
            accountType:accountType,
            withdraw_type:withdraw_type
           })
       }
      },
    methods: {
      arrchange:function(e){
        if(typeof(e.detail.value)!='undefined'&&e.detail.value!='')
        {
          this.setData({
            type:e.detail.value,
            index:e.detail.value
          }) 
        }  
      },
      namechange:function(e){
        if(typeof(e.detail.value)!='undefined'&&e.detail.value!='')
        {
          this.setData({
            name:e.detail.value
          })
        }  
     },
     accountchange:function(e){
      if(typeof(e.detail.value)!='undefined'&&e.detail.value!='')
      {
        this.setData({
          account:e.detail.value
        })
      }
     },
     confirm:function(){
         var that=this
         wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'Distribution_addWithdrawMethod',
            type:typeof(that.data.type)!='undefined'?that.data.type:'',
            name:typeof(that.data.name)!='undefined'?that.data.name:'',
            account:typeof(that.data.account)!='undefined'?that.data.account:'',
            staff_id:wx.getStorageSync('staff_bind_id'),
            user_id:wx.getStorageSync('user_id'),
            distribution_id:wx.getStorageSync('distribution_id')
          },
          success: function(res) {
            if(that.data.page_type==1){
              wx.navigateBack({
                delta: 1,
                success: function() {
                }
              })
            }else{
              wx.redirectTo({
                url: '/yb_shopv2/native/all/index?type=page_applyCw'
              })
            }
            
          }
        })
     }
    }
});
